<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;


class Captcha extends Controller
{
    //点击搜索一下事件
    public function search(Request $req){
        $content = $req->content;
        //查询数据库
        $data = DB::table('captcha')->where('code',$content)->first();
        if($data!==null){
            //有这个网站码
            return ['code'=>200,'message'=>'yes','data'=>$data->id];
        }else{
            //没有这个网站码
            return ['code'=>-1,'message'=>'没找到'];
        }
    }



    /***
     *  +"id": 28
        +"user_id": "123"
        +"code": "aaaa"
        +"title": "测试2"
        +"create_time": "2021-04-21 10:32:55"
        +"update_time": "2021-04-21 10:46:03"
     */

    //获取网址码
    public function getCode(Request $req){
        //根据id查询数据库
        $id = $req->id;
        $a = DB::table('captcha')->where('id',$id)->first();
        // dd($a);
        $url = DB::table('captcha_data')->where('captcha_id',$id)->get();
        foreach($url as $a){
            //后台添加延迟选项，不然前端渲染不出来
            $a->yc = '';
        }
        $messsage = DB::table('captcha')->where('id',$id)->first();
        
        return['code'=>200,'message'=>'获取成功','data'=>[
            'url'=>$url,
            'messsage'=>$messsage->title,
        ]];
    }

}
